Skip to content

fix(core): improve headless mode detection for flags and query args#18855

Merged
galz10 merged 3 commits intomainfrom
galzahavi/fix/headless
Feb 12, 2026
Merged

fix(core): improve headless mode detection for flags and query args#18855
galz10 merged 3 commits intomainfrom
galzahavi/fix/headless

Conversation

@galz10
Copy link
Copy Markdown
Collaborator

@galz10 galz10 commented Feb 11, 2026

Summary

Improve headless mode detection to correctly trust workspaces when using flags like -p, --prompt, -y, and --yolo, or when providing query positional arguments. This ensures that non-interactive commands correctly bypass folder trust prompts.

Details

  • Updated isHeadlessMode in packages/core to detect query arguments and fallback to process.argv for common headless/auto-approve flags.
  • Updated isWorkspaceTrusted in packages/cli to accept and pass headless options, ensuring trust is granted when headless mode is active.
  • Refined interactivity logic in loadCliConfig to stay consistent with the improved headless detection.
  • Fixed TypeScript errors in tests by using canonical Object.defineProperty for system streams instead of delete.

Related Issues

Fixes the issue where npm start -- -y -p "hi" would still trigger folder trust errors.

How to Validate

  1. Run npm start -- -y -p "hi" in an untrusted folder.
  2. Observe that it no longer prompts for folder trust and proceeds with the prompt.
  3. Run npm run test -w @google/gemini-cli-core -- src/utils/headless.test.ts to verify detection logic.
  4. Run npm run build to ensure no regressions in types or linting.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt

@galz10 galz10 requested a review from a team as a code owner February 11, 2026 23:30
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @galz10, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the detection of headless environments within the CLI, ensuring that non-interactive commands bypass folder trust prompts as intended. By expanding the isHeadlessMode logic to recognize common CLI flags and query arguments, and integrating this enhanced detection into the workspace trust mechanism, the system now behaves more predictably and robustly in automated or script-driven scenarios.

Highlights

  • Enhanced Headless Mode Detection: The isHeadlessMode function now more robustly detects headless environments by checking for specific CLI flags (-p, --prompt, -y, --yolo) within process.argv and by considering query arguments.
  • Improved Workspace Trust in Headless Contexts: The isWorkspaceTrusted function in @google/gemini-cli has been updated to accept and utilize headless options, ensuring that folder trust prompts are correctly bypassed when running in a detected headless mode.
  • Refined Interactivity Logic: The loadCliConfig function's interactivity determination logic has been adjusted to align with the enhanced headless mode detection, preventing unintended interactive prompts.
  • Test Infrastructure Fixes: TypeScript errors in test files related to mocking system streams (process.stdout, process.stdin) were resolved by switching from delete to Object.defineProperty for property manipulation.
Changelog
  • packages/cli/src/config/config.ts
    • Modified the call to isWorkspaceTrusted to pass argv.prompt and argv.query as headless options.
    • Updated the interactive variable calculation to include argv.query in the isHeadlessMode check.
  • packages/cli/src/config/trustedFolders.test.ts
    • Added a new test case to verify that isPathTrusted returns true when isHeadlessMode is active.
  • packages/cli/src/config/trustedFolders.ts
    • Imported HeadlessModeOptions type.
    • Modified isPathTrusted to immediately return true if isHeadlessMode is detected with provided options.
    • Updated getWorkspaceTrustFromLocalConfig and isWorkspaceTrusted functions to accept and propagate headlessOptions.
  • packages/core/src/utils/headless.test.ts
    • Added new test cases to confirm isHeadlessMode correctly identifies headless mode when -p, --prompt, -y, or --yolo flags are present in process.argv.
    • Added a test case to confirm isHeadlessMode correctly identifies headless mode when a query option is provided.
    • Replaced delete process.stdout and delete process.stdin with Object.defineProperty in tests to avoid TypeScript errors and correctly mock system streams.
  • packages/core/src/utils/headless.ts
    • Extended isHeadlessMode to check for options?.query and to scan process.argv for -p, --prompt, -y, or --yolo flags, both for integration tests and general execution.
    • Refactored the headless mode detection logic for clarity and robustness.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 11, 2026

Size Change: +382 B (0%)

Total Size: 24.3 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.3 MB +382 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves headless mode detection by considering additional flags and query arguments, which correctly bypasses folder trust prompts in non-interactive scenarios. The changes are consistently applied across the cli and core packages, and the tests have been updated to reflect the new logic. I've included one suggestion to refactor the isHeadlessMode function to reduce code duplication and improve maintainability.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 11, 2026
@galz10 galz10 enabled auto-merge February 12, 2026 00:05
@galz10 galz10 added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit 08e8eea Feb 12, 2026
27 checks passed
@galz10 galz10 deleted the galzahavi/fix/headless branch February 12, 2026 00:30
krsjenmt added a commit to krsjenmt/gemini-cli that referenced this pull request Feb 12, 2026
…ini/gemini-cli (#37)

* fix(cli): resolve double rendering in shpool and address vscode lint warnings (google-gemini#18704)

* feat(plan): document and validate Plan Mode policy overrides (google-gemini#18825)

* Fix pressing any key to exit select mode. (google-gemini#18421)

* fix(cli): update F12 behavior to only open drawer if browser fails (google-gemini#18829)

* feat(plan): allow skills to be enabled in plan mode (google-gemini#18817)

Co-authored-by: Jerop Kipruto <jerop@google.com>

* docs(plan): add documentation for plan mode tools (google-gemini#18827)

* Remove experimental note in extension settings docs (google-gemini#18822)

* Update prompt and grep tool definition to limit context size (google-gemini#18780)

* docs(plan): add `ask_user` tool documentation (google-gemini#18830)

* Revert unintended credentials exposure (google-gemini#18840)

* feat(core): update internal utility models to Gemini 3 (google-gemini#18773)

* feat(a2a): add value-resolver for auth credential resolution (google-gemini#18653)

* Removed getPlainTextLength (google-gemini#18848)

* More grep prompt tweaks (google-gemini#18846)

* refactor(cli): Reactive useSettingsStore hook (google-gemini#14915)

* fix(mcp): Ensure that stdio MCP server execution has the `GEMINI_CLI=1` env variable populated. (google-gemini#18832)

* fix(core): improve headless mode detection for flags and query args (google-gemini#18855)

* refactor(cli): simplify UI and remove legacy inline tool confirmation logic (google-gemini#18566)

* feat(cli): deprecate --allowed-tools and excludeTools in favor of policy engine (google-gemini#18508)

* fix(workflows): improve maintainer detection for automated PR actions (google-gemini#18869)

* refactor(cli): consolidate useToolScheduler and delete legacy implementation (google-gemini#18567)

* Update changelog for v0.28.0 and v0.29.0-preview0 (google-gemini#18819)

* fix(core): ensure sub-agents are registered regardless of tools.allowed (google-gemini#18870)

---------

Co-authored-by: Brad Dux <959674+braddux@users.noreply.github.com>
Co-authored-by: Jerop Kipruto <jerop@google.com>
Co-authored-by: Jacob Richman <jacob314@gmail.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com>
Co-authored-by: christine betts <chrstn@uw.edu>
Co-authored-by: Christian Gunderman <gundermanc@gmail.com>
Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com>
Co-authored-by: Dev Randalpura <devrandalpura@google.com>
Co-authored-by: Pyush Sinha <pyushsinha20@gmail.com>
Co-authored-by: Richie Foreman <richie.foreman@gmail.com>
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Abhijit Balaji <abhijitbalaji@google.com>
Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
Co-authored-by: g-samroberts <158088236+g-samroberts@users.noreply.github.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
@skeshive
Copy link
Copy Markdown
Contributor

/patch

@github-actions
Copy link
Copy Markdown

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: stable,preview
  • Commit: 08e8eeab841fbd16554d01a273f9a67a0825d233
  • Workflows Created: 2

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@github-actions
Copy link
Copy Markdown

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #18904
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@github-actions
Copy link
Copy Markdown

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #18905
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

🚀 Patch Release Started!

📋 Release Details:

  • Environment: prod
  • Channel: preview → publishing to npm tag preview
  • Version: v0.29.0-preview.1
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.29.0-preview.1-pr-18855

⏳ Status: The patch release is now running. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

Patch Release Complete!

📦 Release Details:

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

NTaylorMullen added a commit that referenced this pull request Feb 13, 2026
- Fix regression introduced in #18855 where YOLO mode flags were incorrectly identified as headless mode indicators.

- Update headless mode tests to verify that --yolo remains interactive in a TTY environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants